namespace Guia.Elements
{
    using System;
    using System.Diagnostics.Contracts;
    using System.Windows.Automation;
    using Guia.Locator;

    /// <summary>
    /// This class represents a StatusBar
    /// </summary>
    public class StatusBar : UiElement
    {      
        /// <summary>
        /// Initializes a new instance of the StatusBar class. 
        /// </summary>
        /// <param name="automationElement">The AutomationElement representating the StatusBar.</param>
        public StatusBar(AutomationElement automationElement)
            : base(automationElement)
        {
        }

        /// <summary>
        /// Gets the default-condition to find a control by its type.
        /// </summary>
        public static SearchCondition ControlTypeCondition
        {
            get { return SearchCondition.ByControlType(ControlType.StatusBar); }
        }

        /// <summary>
        /// Get the Label in this StatusBar at the given position.
        /// </summary>
        /// <param name="index">The index of the desired Label.</param>
        /// <returns>The desired Label.</returns>
        /// <exception cref="ArgumentOutOfRangeException">This exception is thrown if the index is out of range.</exception>
        public Label this[int index]
        {
            get
            {
                Contract.Requires<ArgumentOutOfRangeException>(index >= 0 && index < this.GetStatusBarItems().Length);
                return this.GetStatusBarItems()[index];
            }
        }

        /// <summary>
        /// Gets all items of this StatusBar. These items are of the type Label.
        /// </summary>
        /// <returns>
        /// All containing Labels.
        /// </returns>
        [Pure]
        public Label[] GetStatusBarItems()
        {
            return this.GetAll<Label>();
        }
    }
}